package com.zc.iotDevice.controller;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.zc.iotDevice.domain.ChargeStationPort;
import com.zc.iotDevice.service.ChargeStationPortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/station/port")
public class ChargeStationPortController extends BaseController {
    @Autowired
    private ChargeStationPortService portService;

    /**
     * 获取设备状态概率
     */
    @PreAuthorize("@ss.hasPermi('station:port:list')")
    @GetMapping("/getStatus")
    public AjaxResult getStatus(BaseEntity entity)
    {
        return AjaxResult.success(portService.getStatus(entity));
    }

    /**
     * 分页查询
     */
    @PreAuthorize("@ss.hasPermi('station:port:list')")
    @GetMapping("/list")
    @DataScope(deptAlias = "s")
    public TableDataInfo listOfCategoryId(ChargeStationPort port)
    {
        startPage();
        return getDataTable(portService.getList(port));
    }

    /**
     * 查询
     */
    @PreAuthorize("@ss.hasPermi('station:port:info')")
    @GetMapping("/{id}")
    public AjaxResult info(@PathVariable String id)
    {
        return AjaxResult.success(portService.selectByPrimaryKey(id));
    }

    /**
     * 新增
     * @param port 新整参数
     * @return 新增操作结果
     */
    @PreAuthorize("@ss.hasPermi('station:port:add')")
    @Log(title = "新增设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody ChargeStationPort port) {
        return toAjax(portService.insert(port));
    }

    /**
     * 修改
     * @param port 修改参数
     * @return 修改操作结果
     */
    @PreAuthorize("@ss.hasPermi('station:port:edit')")
    @Log(title = "修改设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody ChargeStationPort port) {
        return toAjax(portService.updateByPrimaryKeySelective(port));
    }

    /**
     * 删除
     * @param id id
     * @return 删除操作结果
     */
    @PreAuthorize("@ss.hasPermi('station:port:remove')")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("{id}")
    public AjaxResult remove(@PathVariable String id) {
        return toAjax(portService.deleteByPrimaryKey(id));
    }

    /**
     * 假删除
     * @param id id
     * @return 删除操作结果
     */
    @PreAuthorize("@ss.hasPermi('station:port:del')")
    @Log(title = "假删除", businessType = BusinessType.DELETE)
    @PutMapping("/del/{id}")
    public AjaxResult del(@PathVariable String id) {
        return toAjax(portService.updateDelState(id));
    }
}
